<template>
  <view class="container">
    <!-- 搜索区域 -->
    <view class="search-box">
      <my-search @clickSearch="gotoSearch"></my-search>
    </view>
    <!-- 轮播图区域 -->
    <swiper :indicator-dots="true" :autoplay="true" :circular="true" :duration="1000" :interval="3000">
      <swiper-item v-for="(item,index) in swiperList" :key="index">
        <navigator class="swiper-item" :url="`/subpck/goods_detail/goods_detail?goods_id=${item.goods_id}`">
          <image :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>
    
    <!-- 分类导航区域 -->
    <view class="nav-list">
      <view class="nav-item" v-for="(item,index) in navList" :key="index" @click="navClickHandler(item)">
        <image :src="item.image_src" mode="widthFix"></image>
      </view>
    </view>
    
    <!-- 楼层区域-->
    <view class="floor-list">
      <view class="floor-item" v-for="(item,index) in floorList" :key="index">
        <image :src="item.floor_title.image_src" class="floor-item-title"></image>
        <view class="floor-image-box">
          <navigator class="left-image-box" :url="item.product_list[0].navigator_url">
            <image 
              :src="item.product_list[0].image_src" 
              :style="{ width: item.product_list[0].image_width + 'rpx' }" 
              mode="widthFix"
            ></image>
          </navigator>
          <view class="right-image-box">
            <navigator 
            class="right-image-item" 
            v-for="(item2,index2) in item.product_list.slice(1)" 
            :key="index2"
            :url="item2.navigator_url"
            >
              <image 
                :src="item2.image_src" 
                :style="{width:item2.image_width+'rpx' }"
                mode="widthFix"
              ></image>
            </navigator>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import badgeMin from '@/mixins/tabbar-setBadge.js'
  export default {
    mixins:[badgeMin],
    data() {
      return {
         swiperList:[],
           navList:[],
           floorList:[]
      };
    },
    onLoad() {
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    },
    methods:{
     async getSwiperList(){
             const { data: res } = await uni.$http.get('/api/public/v1/home/swiperdata')
            this.swiperList=res.message
       },
       async getNavList(){
         const {data:res}=await uni.$http.get('/api/public/v1/home/catitems')
         this.navList=res.message
         // console.log(this.navList)
       },
       navClickHandler(item){
         if(item.name==='分类')
         uni.switchTab({
           url:'/pages/cate/cate'
         })
       },
       async getFloorList(){
         const {data:res} =await uni.$http.get('/api/public/v1/home/floordata')
         this.floorList=res.message
         console.log(res.message)
         //处理一下跳转的路径
         this.floorList.forEach(proList=>{
           proList.product_list.forEach(pro=>{
             pro.navigator_url='/subpck/goods_list/goods_list?'+pro.navigator_url.split('?')[1]
           })
         })
         
       },
        // 跳转到分包中的搜索页面
          gotoSearch() {
            uni.navigateTo({
              url: '/subpck/search/search'
            })
          }
    }
  }
</script>

<style lang="scss">
  
  .search-box {
    position: sticky;
    top: 0;
    z-index: 999;
  }
  
  swiper {
    height: 330rpx;
    
    .swiper-item,
    image {
      width: 100%;
      height: 100%;
    }
  }
  
  .nav-list {
    display: flex;
    margin: 15rpx 0;
    justify-content: space-around;
    image {
      width: 128rpx;
      height: 140rpx;
    }
  }
  
  .floor-item-title {
    height: 60rpx;
    width: 100%;
    display: flex;
  }
  .floor-image-box {
    display: flex;
    padding-left: 15rpx;
    .right-image-box {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around
    }
    
  }
</style>
